# -*- coding: UTF-8 -*-

# FileName     : response
# Author       : EastsunW eastsunw@foxmail.com
# Create at    : 2022-04-22 18:19
# Last Modified: 2022-04-22 18:19
# Modified By  : EastsunW
# -------------
# Description  : 用于TF的自动补全，输入部分名字，返回匹配结果
# -------------

from flask_restful import Resource, fields, marshal_with, reqparse
from Server.Utils.MongoDB import mongo


class PWM_Class(Resource):
    # 返回数据的格式
    pwm_fields = {
        "motif": fields.List(fields.List(fields.Float))
    }

    @marshal_with(pwm_fields)
    def post(self):
        """返回TF可选列表
        Arguments：
            query (str) : 输入的内容
        Returns:
            {
                rsIDs : String[]
            }
        """
        # 获取参数：当前页码，每页结果数，查询类型和查询名称
        parser = reqparse.RequestParser()
        parser.add_argument(
            'motif', type=str,
            required=True,
            nullable=False
        )
        request_args = parser.parse_args()
        raw_result = mongo.db\
            .get_collection("pwm")\
            .find_one({"ID": request_args["motif"]})
        pwm_by_site = []
        for i in zip(
            raw_result["PWM"][0],
            raw_result["PWM"][1],
            raw_result["PWM"][2],
            raw_result["PWM"][3]
        ):
            pwm_by_site.append(list(i))
        return {
            "motif": pwm_by_site
        }
